import { createSlice } from "@reduxjs/toolkit";
import { RootState } from "../index";

interface assState {
  isAdd: boolean; //添加 或 修改
  addImg: number; // 1 添加 0 修改 -1跳出
  assInfo: object; //修改时的信息

  update: boolean;
}

const initialState: assState = {
  isAdd: true,
  addImg: 1,
  assInfo: {},
  update: false,
};

const assStore = createSlice({
  name: "ass",
  initialState,
  reducers: {
    changeisAddState(state, action) {
      state.isAdd = action.payload;
    },
    changeaddImgState(state, action) {
      state.addImg = action.payload;
    },
    changeAssInfoState(state, action) {
      state.assInfo = action.payload;
    },
    changeupdateState(state, action) {
      state.update = action.payload;
    },
  },
});

export const selectAss = (state: RootState) => state.ass.isAdd;
export const {
  changeisAddState,
  changeAssInfoState,
  changeaddImgState,
  changeupdateState,
} = assStore.actions;
export default assStore.reducer;
